package templates;

public final class Template {

    private short uid;
    private String name;
    private String alias;
    private String tableName;
    private Iterable<PropertyTemplate> propertyTemplates;
    private Iterable<PresentationTemplate> presentationTemplates;

    public Template() {
        name = null;
        alias = null;
        tableName = null;
        propertyTemplates = null;
        presentationTemplates = null;
    }

    public Template(short uid, String name, String alias, String tableName, Iterable<PropertyTemplate> propierties, Iterable<PresentationTemplate> presentations) {
        this.uid = uid;
        this.name = name;
        this.alias = alias;
        this.tableName = tableName;
        this.propertyTemplates = propierties;
        this.presentationTemplates = presentations;

    }

    public short getUid() {
        return uid;
    }

    public String getName() {
        return name;
    }

    public String getAlias() {
        return alias;
    }

    public String getTableName() {
        return tableName;
    }

    public Iterable<PropertyTemplate> getPropertyTemplateCollection() {
        return propertyTemplates;
    }

    public Iterable<PresentationTemplate> getPresentationTemplateCollection() {
        return presentationTemplates;
    }

    public PropertyTemplate getPropertyTemplate(short uid) {
        PropertyTemplate result = null;
        for (PropertyTemplate pt : propertyTemplates) {
            if (pt.getUid() == uid) {
                result = pt;
                break;
            }
        }
        return result;
    }

    public short getPropertyTemplateUIdByPropertyName(String propertyName) {
        Short result = null;
        for (PropertyTemplate pt : propertyTemplates) {
            if (propertyName.equals(pt.getName())) {
                result = pt.getUid();
                break;
            }
        }
        return result;
    }

    public PresentationTemplate getPresentationTemplate(short uid) {
        PresentationTemplate result = null;
        for (PresentationTemplate pt : presentationTemplates) {
            if (pt.getUid() == uid) {
                result = pt;
                break;
            }
        }
        return result;
    }

    public PresentationTemplate getPresentationTemplate(String templateAlias) {
        PresentationTemplate result = null;
        for (PresentationTemplate pt : presentationTemplates) {
            if (pt.getAlias().equals(templateAlias)) {
                result = pt;
                break;
            }
        }
        return result;
    }
}